import request from '@/utils/request'
import { getToken } from '@/utils/auth'

// 采购列表
export function fetchList(query) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/pas/purchase/getPurchases',
    method: 'get',
    params: query
  })
}

// 通过id查找明细
export function queryByPurchaseId(purchaseId) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/pas/purchaseItem/getItemByPurchaseId/' + purchaseId,
    method: 'get',
    params: null
  })
}

// 采购提交、审批
export function approvalPurchase(query) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/pas/purchase/approvalPurchase/',
    method: 'post',
    params: query
  })
}

// 采购删除
export function purchaseDelete(purchaseId) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/pas/purchase/purchaseDelete/' + purchaseId,
    method: 'get',
    params: null
  })
}

// sku
export function skuList(query) { // 新增采购单
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/pas/sku/listAll',
    method: 'get',
    params: query
  })
}

// 加载仓库
export function queryWarehouseList(query) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/pas/warehouse/queryList',
    method: 'get',
    params: query
  })
}

// 加载供应商
export function querySupplierList(query) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/pas/supplier/list',
    method: 'get',
    params: query
  })
}

// 创建编辑采购单
export function createEditPurchaseOrder(query) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/pas/purchase/createEditPurchaseOrder',
    method: 'post',
    params: query
  })
}

// 采购履历
export function getPurchasesHistory(query) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/pas/purchase/getPurchasesHistory',
    method: 'get',
    params: query
  })
}

// 采购完成
export function purchaseOver(purchaseId) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/pas/purchase/purchaseOver/' + purchaseId,
    method: 'get',
    params: null
  })
}

// 发票
export function purchaseInvoice(data) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/pas/purchase/purchaseInvoice',
    method: 'post',
    params: data
  })
}
